package com.dks.controller;

import com.dks.models.Times;
import com.dks.repository.ITimesRepository;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 学生班级相关
 */
@RestController
@RequestMapping("times")
public class TimesController {

    @Resource
    private ITimesRepository timesRepository;

    /**
     * 提交时间段
     *
     * @param times 记录
     * @author zn
     */
    @PostMapping("insert")
    public ResultModel<Boolean> insert(@RequestBody Times times) {
        return timesRepository.insert(times);
    }

    /**
     * 修改记录
     *
     * @param Times id 课程系列id
     * @author zn
     */
    @PostMapping("update")
    public ResultModel<Boolean> update(@RequestBody Times Times) {
        return timesRepository.update(Times);
    }

    /**
     * 查找列表
     *
     * @author zn
     */
    @GetMapping("selectList")
    public ResultModel<PageInfo<Times>> selectList(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("beginTime") String beginTime) {
        return timesRepository.selectList(pageNum, pageSize, beginTime);
    }

    /**
     * id查找
     *
     * @author zn
     */
    @GetMapping("selectById")
    public ResultModel<PageInfo<Times>> selectById(@Param("id") Integer id) {
        return timesRepository.selectById(id);
    }

    /**
     * 查找 有效时间段
     *
     * @author zn
     */
    @GetMapping("selectEffectiveTime")
    public ResultModel<String> selectEffectiveTime(@Param("time") String time, @Param("timeSlot") Integer timeSlot, @Param("id") Integer id, @Param("AmOrPm") String AmOrPm) {
        return timesRepository.selectEffectiveTime(time, timeSlot, id, AmOrPm);
    }


    /**
     * 删除记录
     *
     * @param Times 记录
     * @author zn
     */
    @PostMapping("delete")
    public ResultModel<Boolean> delete(@RequestBody Times Times) {
        return timesRepository.delete(Times);
    }


}
